/**
 * Helper class for writing a standard 
 * packet
 */
package networkcom;

import java.io.IOException;
import java.io.OutputStream;

public class PacketOutputStream extends OutputStream{

	private OutputStream out;
	public PacketOutputStream(OutputStream out){
		this.out = out;
	}
	@Override
	public void write(int arg0) throws IOException {
		out.write(arg0);
	}
	
	/**
	 * Write a standard packet in a form
	 * that the client can easily parse
	 * @param p
	 */
	public void writePacket(Packet p){
		try {
			out.write(p.getOpcode());
			if(p.getRawData()!= null){
				out.write(p.getRawData().length);
				out.write(p.getRawData());
			}
			out.flush();
		} catch (IOException e) {}
	}
	

}
